﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.Shared;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmBangcandoitk.
	/// </summary>
	public class frmBangcandoitk : System.Windows.Forms.Form
	{
		//Khai bao gia tri mau cho form
		private int i_Red=255,i_Green=255,i_Blue=195;

		//Khai bao bien su dung trong form.
		#region Khai bao cac bien su dung trong form.
		private string s_Tenform="",s_fTieude_chinh="",s_Pagesize="A4";
		private int i_HChuong=6,i_HLoaikhoan=4,i_HHoatdong=0,i_Kieuin=1, i_Banin=1;
		private int i_userid=0;
		
		private Print_kt Print=new Print_kt();
		private LibKetoan.AccessData a;
		private exportExcel exportExcel=new exportExcel();
		private System.Data.DataRow r;
		private System.Data.DataTable dt_Dmchuong,dt_Dmlk,dt_Dmhoatdong,dt_Dmnhombc;
		private System.Data.DataSet ds_Data;
		private string s_Report="";
		#endregion Khai bao bien su dung trong form.

		#region Cac control su dung trong form.

		private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butKetthuc;
		private txtListBox.txtListBox txtLoaikhoan;
		protected txtListBox.txtListBox txtTenloaikhoan;
		private System.Windows.Forms.GroupBox grbThang;
		private System.Windows.Forms.Label lblLoaikhoan;
		private txtListBox.txtListBox txtTenhoatdong;
		private System.Windows.Forms.Label lblHoatdong;
		private txtListBox.txtListBox txtHoatdong;
		private txtListBox.txtListBox txtChuong;
		private txtListBox.txtListBox txtTenchuong;
		private System.Windows.Forms.Label lblChuong;
		private System.Windows.Forms.Button butExcel;
		private System.Windows.Forms.Label lblNhombc;
		private System.Windows.Forms.ComboBox cboNhombc;
		private System.Windows.Forms.ComboBox cboChonthang;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.NumericUpDown numDenthang;
		private System.Windows.Forms.NumericUpDown numTuthang;
		private System.Windows.Forms.NumericUpDown numNam;
		private System.Windows.Forms.Label lblDenthang;
		private System.Windows.Forms.Label lblTuthang;
		private System.Windows.Forms.Label lblNam;
		private System.Windows.Forms.CheckBox chkChitiet;
		private System.Windows.Forms.GroupBox grpNen;
		private LibList.List listHoatdong;
		private LibList.List listChuong;
		private LibList.List listLoaikhoan;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
	
		#endregion Cac control su dung trong form.

		public frmBangcandoitk(LibKetoan.AccessData acc,int userid)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;
			//s_Tenform=s_Form;
			s_Tenform="BCDTK";
			i_userid=userid;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
			try
			{
				a.Dispose();
				ds_Data.Dispose();
				dt_Dmchuong.Dispose();
				dt_Dmlk.Dispose();
				dt_Dmhoatdong.Dispose();
				GC.Collect();
			}
			catch{};
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmBangcandoitk));
			this.butXem = new System.Windows.Forms.Button();
			this.butIn = new System.Windows.Forms.Button();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.lblLoaikhoan = new System.Windows.Forms.Label();
			this.txtLoaikhoan = new txtListBox.txtListBox();
			this.txtTenloaikhoan = new txtListBox.txtListBox();
			this.grbThang = new System.Windows.Forms.GroupBox();
			this.txtTenhoatdong = new txtListBox.txtListBox();
			this.lblHoatdong = new System.Windows.Forms.Label();
			this.txtHoatdong = new txtListBox.txtListBox();
			this.txtChuong = new txtListBox.txtListBox();
			this.lblChuong = new System.Windows.Forms.Label();
			this.txtTenchuong = new txtListBox.txtListBox();
			this.butExcel = new System.Windows.Forms.Button();
			this.lblNhombc = new System.Windows.Forms.Label();
			this.cboNhombc = new System.Windows.Forms.ComboBox();
			this.cboChonthang = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.numDenthang = new System.Windows.Forms.NumericUpDown();
			this.numTuthang = new System.Windows.Forms.NumericUpDown();
			this.numNam = new System.Windows.Forms.NumericUpDown();
			this.lblDenthang = new System.Windows.Forms.Label();
			this.lblTuthang = new System.Windows.Forms.Label();
			this.lblNam = new System.Windows.Forms.Label();
			this.chkChitiet = new System.Windows.Forms.CheckBox();
			this.grpNen = new System.Windows.Forms.GroupBox();
			this.listChuong = new LibList.List();
			this.listLoaikhoan = new LibList.List();
			this.listHoatdong = new LibList.List();
			((System.ComponentModel.ISupportInitialize)(this.numDenthang)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numTuthang)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).BeginInit();
			this.SuspendLayout();
			// 
			// butXem
			// 
			this.butXem.BackColor = System.Drawing.SystemColors.Control;
			this.butXem.ForeColor = System.Drawing.Color.Black;
			this.butXem.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXem.Image")));
			this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXem.Location = new System.Drawing.Point(103, 214);
			this.butXem.Name = "butXem";
			this.butXem.Size = new System.Drawing.Size(68, 25);
			this.butXem.TabIndex = 80;
			this.butXem.Text = "     &Xem";
			this.butXem.Click += new System.EventHandler(this.butXem_Click);
			this.butXem.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// butIn
			// 
			this.butIn.BackColor = System.Drawing.SystemColors.Control;
			this.butIn.ForeColor = System.Drawing.Color.Black;
			this.butIn.Image = ((System.Drawing.Bitmap)(resources.GetObject("butIn.Image")));
			this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butIn.Location = new System.Drawing.Point(245, 214);
			this.butIn.Name = "butIn";
			this.butIn.Size = new System.Drawing.Size(68, 25);
			this.butIn.TabIndex = 82;
			this.butIn.Text = "     &In";
			this.butIn.Click += new System.EventHandler(this.butIn_Click);
			this.butIn.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// butKetthuc
			// 
			this.butKetthuc.BackColor = System.Drawing.SystemColors.Control;
			this.butKetthuc.ForeColor = System.Drawing.Color.Black;
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(316, 214);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(68, 25);
			this.butKetthuc.TabIndex = 83;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			this.butKetthuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// lblLoaikhoan
			// 
			this.lblLoaikhoan.BackColor = System.Drawing.SystemColors.Control;
			this.lblLoaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblLoaikhoan.Location = new System.Drawing.Point(16, 89);
			this.lblLoaikhoan.Name = "lblLoaikhoan";
			this.lblLoaikhoan.Size = new System.Drawing.Size(80, 23);
			this.lblLoaikhoan.TabIndex = 23;
			this.lblLoaikhoan.Text = "Loại khoản :";
			this.lblLoaikhoan.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtLoaikhoan
			// 
			this.txtLoaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtLoaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtLoaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtLoaikhoan.Location = new System.Drawing.Point(103, 89);
			this.txtLoaikhoan.Name = "txtLoaikhoan";
			this.txtLoaikhoan.Size = new System.Drawing.Size(63, 21);
			this.txtLoaikhoan.TabIndex = 24;
			this.txtLoaikhoan.Text = "";
			this.txtLoaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLoaikhoan_KeyDown);
			this.txtLoaikhoan.DoubleClick += new System.EventHandler(this.txtLoaikhoan_DoubleClick);
			this.txtLoaikhoan.Validated += new System.EventHandler(this.txtLoaikhoan_Validated);
			this.txtLoaikhoan.TextChanged += new System.EventHandler(this.txtLoaikhoan_TextChanged);
			// 
			// txtTenloaikhoan
			// 
			this.txtTenloaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTenloaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTenloaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTenloaikhoan.Location = new System.Drawing.Point(168, 89);
			this.txtTenloaikhoan.Name = "txtTenloaikhoan";
			this.txtTenloaikhoan.ReadOnly = true;
			this.txtTenloaikhoan.Size = new System.Drawing.Size(296, 21);
			this.txtTenloaikhoan.TabIndex = 25;
			this.txtTenloaikhoan.TabStop = false;
			this.txtTenloaikhoan.Text = "";
			this.txtTenloaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// grbThang
			// 
			this.grbThang.Enabled = false;
			this.grbThang.Location = new System.Drawing.Point(9, 5);
			this.grbThang.Name = "grbThang";
			this.grbThang.Size = new System.Drawing.Size(470, 50);
			this.grbThang.TabIndex = 1;
			this.grbThang.TabStop = false;
			// 
			// txtTenhoatdong
			// 
			this.txtTenhoatdong.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTenhoatdong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTenhoatdong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTenhoatdong.Location = new System.Drawing.Point(168, 112);
			this.txtTenhoatdong.Name = "txtTenhoatdong";
			this.txtTenhoatdong.ReadOnly = true;
			this.txtTenhoatdong.Size = new System.Drawing.Size(296, 21);
			this.txtTenhoatdong.TabIndex = 28;
			this.txtTenhoatdong.TabStop = false;
			this.txtTenhoatdong.Text = "";
			this.txtTenhoatdong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// lblHoatdong
			// 
			this.lblHoatdong.BackColor = System.Drawing.SystemColors.Control;
			this.lblHoatdong.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblHoatdong.Location = new System.Drawing.Point(16, 112);
			this.lblHoatdong.Name = "lblHoatdong";
			this.lblHoatdong.Size = new System.Drawing.Size(80, 23);
			this.lblHoatdong.TabIndex = 26;
			this.lblHoatdong.Text = "Hoạt động :";
			this.lblHoatdong.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtHoatdong
			// 
			this.txtHoatdong.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtHoatdong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtHoatdong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtHoatdong.Location = new System.Drawing.Point(103, 112);
			this.txtHoatdong.Name = "txtHoatdong";
			this.txtHoatdong.Size = new System.Drawing.Size(63, 21);
			this.txtHoatdong.TabIndex = 27;
			this.txtHoatdong.Text = "";
			this.txtHoatdong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtHoatdong_KeyDown);
			this.txtHoatdong.DoubleClick += new System.EventHandler(this.txtHoatdong_DoubleClick);
			this.txtHoatdong.Validated += new System.EventHandler(this.txtHoatdong_Validated);
			this.txtHoatdong.TextChanged += new System.EventHandler(this.txtHoatdong_TextChanged);
			// 
			// txtChuong
			// 
			this.txtChuong.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtChuong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtChuong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtChuong.Location = new System.Drawing.Point(103, 66);
			this.txtChuong.Name = "txtChuong";
			this.txtChuong.Size = new System.Drawing.Size(63, 21);
			this.txtChuong.TabIndex = 21;
			this.txtChuong.Text = "";
			this.txtChuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtChuong_KeyDown);
			this.txtChuong.DoubleClick += new System.EventHandler(this.txtChuong_DoubleClick);
			this.txtChuong.Validated += new System.EventHandler(this.txtChuong_Validated);
			this.txtChuong.TextChanged += new System.EventHandler(this.txtChuong_TextChanged);
			// 
			// lblChuong
			// 
			this.lblChuong.BackColor = System.Drawing.SystemColors.Control;
			this.lblChuong.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblChuong.Location = new System.Drawing.Point(16, 66);
			this.lblChuong.Name = "lblChuong";
			this.lblChuong.Size = new System.Drawing.Size(80, 23);
			this.lblChuong.TabIndex = 20;
			this.lblChuong.Text = "Chương :";
			this.lblChuong.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtTenchuong
			// 
			this.txtTenchuong.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTenchuong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTenchuong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTenchuong.Location = new System.Drawing.Point(168, 66);
			this.txtTenchuong.Name = "txtTenchuong";
			this.txtTenchuong.ReadOnly = true;
			this.txtTenchuong.Size = new System.Drawing.Size(296, 21);
			this.txtTenchuong.TabIndex = 22;
			this.txtTenchuong.TabStop = false;
			this.txtTenchuong.Text = "";
			this.txtTenchuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// butExcel
			// 
			this.butExcel.BackColor = System.Drawing.SystemColors.Control;
			this.butExcel.ForeColor = System.Drawing.Color.Black;
			this.butExcel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butExcel.Image")));
			this.butExcel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butExcel.Location = new System.Drawing.Point(174, 214);
			this.butExcel.Name = "butExcel";
			this.butExcel.Size = new System.Drawing.Size(68, 25);
			this.butExcel.TabIndex = 81;
			this.butExcel.Text = "     &Excel";
			this.butExcel.Click += new System.EventHandler(this.butExcel_Click);
			this.butExcel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// lblNhombc
			// 
			this.lblNhombc.BackColor = System.Drawing.SystemColors.Control;
			this.lblNhombc.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblNhombc.Location = new System.Drawing.Point(12, 135);
			this.lblNhombc.Name = "lblNhombc";
			this.lblNhombc.Size = new System.Drawing.Size(86, 23);
			this.lblNhombc.TabIndex = 29;
			this.lblNhombc.Text = "Nhóm báo cáo :";
			this.lblNhombc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// cboNhombc
			// 
			this.cboNhombc.BackColor = System.Drawing.SystemColors.HighlightText;
			this.cboNhombc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboNhombc.ForeColor = System.Drawing.Color.DarkBlue;
			this.cboNhombc.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.cboNhombc.Items.AddRange(new object[] {
														   "Tất cả",
														   "Tài khoản nợ",
														   "Tài khoản có"});
			this.cboNhombc.Location = new System.Drawing.Point(103, 135);
			this.cboNhombc.Name = "cboNhombc";
			this.cboNhombc.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboNhombc.Size = new System.Drawing.Size(362, 21);
			this.cboNhombc.TabIndex = 30;
			this.cboNhombc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.cboNhombc.Leave += new System.EventHandler(this.cboNhombc_Leave);
			this.cboNhombc.Enter += new System.EventHandler(this.cboNhombc_Enter);
			// 
			// cboChonthang
			// 
			this.cboChonthang.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboChonthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboChonthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.cboChonthang.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.cboChonthang.Items.AddRange(new object[] {
															  " Tháng",
															  " Quý",
															  " Năm"});
			this.cboChonthang.Location = new System.Drawing.Point(103, 21);
			this.cboChonthang.Name = "cboChonthang";
			this.cboChonthang.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboChonthang.Size = new System.Drawing.Size(107, 21);
			this.cboChonthang.TabIndex = 11;
			this.cboChonthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.cboChonthang.SelectedIndexChanged += new System.EventHandler(this.cboChonthang_SelectedIndexChanged);
			this.cboChonthang.Leave += new System.EventHandler(this.cboChonthang_Leave);
			this.cboChonthang.Enter += new System.EventHandler(this.cboChonthang_Enter);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.Control;
			this.label1.ForeColor = System.Drawing.Color.DarkBlue;
			this.label1.Location = new System.Drawing.Point(16, 21);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 23);
			this.label1.TabIndex = 10;
			this.label1.Text = "Báo cáo theo :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// numDenthang
			// 
			this.numDenthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numDenthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.numDenthang.Location = new System.Drawing.Point(340, 21);
			this.numDenthang.Maximum = new System.Decimal(new int[] {
																		12,
																		0,
																		0,
																		0});
			this.numDenthang.Minimum = new System.Decimal(new int[] {
																		1,
																		0,
																		0,
																		0});
			this.numDenthang.Name = "numDenthang";
			this.numDenthang.Size = new System.Drawing.Size(38, 21);
			this.numDenthang.TabIndex = 15;
			this.numDenthang.Value = new System.Decimal(new int[] {
																	  1,
																	  0,
																	  0,
																	  0});
			this.numDenthang.Enter += new System.EventHandler(this.numDenthang_Enter);
			this.numDenthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numDenthang.Leave += new System.EventHandler(this.numDenthang_Leave);
			// 
			// numTuthang
			// 
			this.numTuthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numTuthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.numTuthang.Location = new System.Drawing.Point(266, 21);
			this.numTuthang.Maximum = new System.Decimal(new int[] {
																	   12,
																	   0,
																	   0,
																	   0});
			this.numTuthang.Minimum = new System.Decimal(new int[] {
																	   1,
																	   0,
																	   0,
																	   0});
			this.numTuthang.Name = "numTuthang";
			this.numTuthang.Size = new System.Drawing.Size(38, 21);
			this.numTuthang.TabIndex = 13;
			this.numTuthang.Value = new System.Decimal(new int[] {
																	 1,
																	 0,
																	 0,
																	 0});
			this.numTuthang.Enter += new System.EventHandler(this.numTuthang_Enter);
			this.numTuthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numTuthang.Leave += new System.EventHandler(this.numTuthang_Leave);
			// 
			// numNam
			// 
			this.numNam.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numNam.ForeColor = System.Drawing.Color.DarkBlue;
			this.numNam.Location = new System.Drawing.Point(416, 21);
			this.numNam.Maximum = new System.Decimal(new int[] {
																   3004,
																   0,
																   0,
																   0});
			this.numNam.Minimum = new System.Decimal(new int[] {
																   2004,
																   0,
																   0,
																   0});
			this.numNam.Name = "numNam";
			this.numNam.Size = new System.Drawing.Size(48, 21);
			this.numNam.TabIndex = 17;
			this.numNam.Value = new System.Decimal(new int[] {
																 2004,
																 0,
																 0,
																 0});
			this.numNam.Enter += new System.EventHandler(this.numNam_Enter);
			this.numNam.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numNam.Leave += new System.EventHandler(this.numNam_Leave);
			// 
			// lblDenthang
			// 
			this.lblDenthang.BackColor = System.Drawing.SystemColors.Control;
			this.lblDenthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblDenthang.Location = new System.Drawing.Point(303, 21);
			this.lblDenthang.Name = "lblDenthang";
			this.lblDenthang.Size = new System.Drawing.Size(32, 23);
			this.lblDenthang.TabIndex = 14;
			this.lblDenthang.Text = "đến ";
			this.lblDenthang.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblTuthang
			// 
			this.lblTuthang.BackColor = System.Drawing.SystemColors.Control;
			this.lblTuthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblTuthang.Location = new System.Drawing.Point(210, 21);
			this.lblTuthang.Name = "lblTuthang";
			this.lblTuthang.Size = new System.Drawing.Size(49, 23);
			this.lblTuthang.TabIndex = 12;
			this.lblTuthang.Text = "Từ tháng";
			this.lblTuthang.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblNam
			// 
			this.lblNam.BackColor = System.Drawing.SystemColors.Control;
			this.lblNam.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblNam.Location = new System.Drawing.Point(377, 21);
			this.lblNam.Name = "lblNam";
			this.lblNam.Size = new System.Drawing.Size(34, 23);
			this.lblNam.TabIndex = 15;
			this.lblNam.Text = "năm";
			this.lblNam.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// chkChitiet
			// 
			this.chkChitiet.Checked = true;
			this.chkChitiet.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chkChitiet.ForeColor = System.Drawing.Color.DarkBlue;
			this.chkChitiet.Location = new System.Drawing.Point(103, 159);
			this.chkChitiet.Name = "chkChitiet";
			this.chkChitiet.TabIndex = 31;
			this.chkChitiet.Text = "Chi tiết";
			this.chkChitiet.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// grpNen
			// 
			this.grpNen.BackColor = System.Drawing.SystemColors.Control;
			this.grpNen.Location = new System.Drawing.Point(9, 49);
			this.grpNen.Name = "grpNen";
			this.grpNen.Size = new System.Drawing.Size(470, 139);
			this.grpNen.TabIndex = 2;
			this.grpNen.TabStop = false;
			// 
			// listChuong
			// 
			this.listChuong.BackColor = System.Drawing.SystemColors.Info;
			this.listChuong.ColumnCount = 0;
			this.listChuong.Location = new System.Drawing.Point(200, 192);
			this.listChuong.MatchBufferTimeOut = 1000;
			this.listChuong.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listChuong.Name = "listChuong";
			this.listChuong.Size = new System.Drawing.Size(75, 17);
			this.listChuong.TabIndex = 107;
			this.listChuong.TextIndex = -1;
			this.listChuong.TextMember = null;
			this.listChuong.ValueIndex = -1;
			this.listChuong.Visible = false;
			// 
			// listLoaikhoan
			// 
			this.listLoaikhoan.BackColor = System.Drawing.SystemColors.Info;
			this.listLoaikhoan.ColumnCount = 0;
			this.listLoaikhoan.Location = new System.Drawing.Point(120, 192);
			this.listLoaikhoan.MatchBufferTimeOut = 1000;
			this.listLoaikhoan.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listLoaikhoan.Name = "listLoaikhoan";
			this.listLoaikhoan.Size = new System.Drawing.Size(75, 17);
			this.listLoaikhoan.TabIndex = 106;
			this.listLoaikhoan.TextIndex = -1;
			this.listLoaikhoan.TextMember = null;
			this.listLoaikhoan.ValueIndex = -1;
			this.listLoaikhoan.Visible = false;
			// 
			// listHoatdong
			// 
			this.listHoatdong.BackColor = System.Drawing.SystemColors.Info;
			this.listHoatdong.ColumnCount = 0;
			this.listHoatdong.Location = new System.Drawing.Point(32, 192);
			this.listHoatdong.MatchBufferTimeOut = 1000;
			this.listHoatdong.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listHoatdong.Name = "listHoatdong";
			this.listHoatdong.Size = new System.Drawing.Size(75, 17);
			this.listHoatdong.TabIndex = 105;
			this.listHoatdong.TextIndex = -1;
			this.listHoatdong.TextMember = null;
			this.listHoatdong.ValueIndex = -1;
			this.listHoatdong.Visible = false;
			// 
			// frmBangcandoitk
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(486, 252);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.chkChitiet,
																		  this.cboChonthang,
																		  this.label1,
																		  this.numDenthang,
																		  this.numTuthang,
																		  this.numNam,
																		  this.lblDenthang,
																		  this.lblTuthang,
																		  this.lblNam,
																		  this.cboNhombc,
																		  this.lblNhombc,
																		  this.butExcel,
																		  this.txtTenchuong,
																		  this.txtChuong,
																		  this.lblChuong,
																		  this.txtHoatdong,
																		  this.txtLoaikhoan,
																		  this.lblHoatdong,
																		  this.lblLoaikhoan,
																		  this.txtTenhoatdong,
																		  this.txtTenloaikhoan,
																		  this.butXem,
																		  this.butKetthuc,
																		  this.butIn,
																		  this.grbThang,
																		  this.grpNen,
																		  this.listChuong,
																		  this.listLoaikhoan,
																		  this.listHoatdong});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "frmBangcandoitk";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.TopMost = true;
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmBangcandoitk_Closing);
			this.Load += new System.EventHandler(this.frmBangcandoitk_Load);
			((System.ComponentModel.ISupportInitialize)(this.numDenthang)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numTuthang)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		
		private void frmBangcandoitk_Load(object sender, System.EventArgs e)
		{
			//Gan gia tri khoi tao cho cac o thang nam
			cboChonthang.SelectedIndex=0;
			numTuthang.Maximum=12; numTuthang.Minimum=1;
			numDenthang.Maximum=12; numDenthang.Minimum=1;
			numTuthang.Value=DateTime.Now.Month;
			numDenthang.Value=DateTime.Now.Month;
			numNam.Value=DateTime.Now.Year;
			//
			f_Loaddm();
			s_Pagesize="A4";
			i_Banin=1;i_Kieuin=2;
			s_fTieude_chinh="BẢNG CÂN ĐỐI TÀI KHOẢN";
			s_Report="KT_Bangcandoitk.rpt";
			this.Text="Bảng cân đối tài khoản.";
			cboChonthang.Focus();
			cboNhombc.SelectedIndex=-1;
		}

		private void f_Loaddm()
		{
			string s_Danhmuc=s_Tenform;
			f_LoadChuong();
			f_LoadLoaikhoan();
			f_LoadNhombc();
			switch (s_Danhmuc)
			{
				case "BCDTK":
					f_LoadHoatdong();
					break;
				default:
					break;
			}
		}


		#region Load danh muc vao cac list.
		private void f_LoadChuong()
		{
			listChuong.DisplayMember="TEN";
			listChuong.TextMember="MA";
			listChuong.ValueMember="TEN";

			dt_Dmchuong=a.get_DMChuong().Tables[0];
			listChuong.DataSource=dt_Dmchuong;
		}

		private void f_LoadLoaikhoan()
		{
			listLoaikhoan.DisplayMember="TLK";
			listLoaikhoan.TextMember="LK";
			listLoaikhoan.ValueMember="TLK";

			dt_Dmlk=a.get_DMLoaikhoan().Tables[0];
			listLoaikhoan.DataSource=dt_Dmlk;
		}

		private void f_LoadHoatdong()
		{
			listHoatdong.DisplayMember="TEN";
			listHoatdong.TextMember="MA";
			listHoatdong.ValueMember="TEN";

			dt_Dmhoatdong=a.get_DMHoatdong().Tables[0];
			listHoatdong.DataSource=dt_Dmhoatdong;
		}

		private void f_LoadNhombc()
		{
			dt_Dmnhombc=a.get_DMNhombc().Tables[0];

			cboNhombc.DisplayMember="TEN";
			cboNhombc.ValueMember="ID";
			cboNhombc.DataSource=dt_Dmnhombc;
			cboNhombc.SelectedIndex=-1;
		}
		#endregion Load danh muc vao cac list.

		private void f_Hide_List()
		{
			if(!listChuong.Focused) listChuong.Hide();
			if(!listLoaikhoan.Focused) listLoaikhoan.Hide();
			if(!listHoatdong.Focused) listHoatdong.Hide();
		}
		
		#region Cac su kien thay doi mau sac khi focus den control.
		private void event_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab || e.KeyValue==13)
			{
				SendKeys.Send("{Tab}");
			}
		}
		
		private void numTuthang_Enter(object sender, System.EventArgs e)
		{
			this.numTuthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numDenthang_Enter(object sender, System.EventArgs e)
		{
			this.numDenthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void cboChonthang_Enter(object sender, System.EventArgs e)
		{
			this.cboChonthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void cboNhombc_Enter(object sender, System.EventArgs e)
		{
			this.cboNhombc.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numNam_Enter(object sender, System.EventArgs e)
		{
			this.numNam.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numTuthang_Leave(object sender, System.EventArgs e)
		{
			this.numTuthang.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numDenthang_Leave(object sender, System.EventArgs e)
		{
			this.numDenthang.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numNam_Leave(object sender, System.EventArgs e)
		{
			this.numNam.BackColor = System.Drawing.SystemColors.Window;
		}

		private void cboChonthang_Leave(object sender, System.EventArgs e)
		{
			this.cboChonthang.BackColor = System.Drawing.SystemColors.Window;
			try {if (lblNhombc.Visible) cboNhombc.SelectedIndex=-1;}
			catch{}
		}

		private void cboNhombc_Leave(object sender, System.EventArgs e)
		{
			this.cboNhombc.BackColor = System.Drawing.SystemColors.Window;
		}

		#endregion Thay doi mau khi focus den control.

		private void Filter_List(LibList.List listDulieu,string s_Dkloc,string s_Tenfield_1,string s_Tenfield_2)
		{
			try
			{
				string s_Dieukien=s_Tenfield_1.Trim()+" like '%"+s_Dkloc.Trim()+"%'";
				if (s_Tenfield_2.Trim()!="") s_Dieukien+=" or "+s_Tenfield_2.Trim()+" like '%"+s_Dkloc.Trim()+"%'";
				CurrencyManager cm= (CurrencyManager)BindingContext[listDulieu.DataSource];
				System.Data.DataView dv=(System.Data.DataView)cm.List;
				dv.RowFilter=s_Dieukien;
			}
			catch{}
		}


		#region Cac su kien xu ly list khi focus den control.
		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void txtChuong_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (dt_Dmchuong!=null)
			{
				if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listChuong.Focus();
				else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
				{
					if (listChuong.Visible) 
					{
						listChuong.Focus();
						SendKeys.Send("{Down}");
					}
					else SendKeys.Send("{Tab}");
				}
			}
			else SendKeys.Send("{Tab}");
		}

		private void txtChuong_DoubleClick(object sender, System.EventArgs e)
		{
			if (dt_Dmchuong!=null)
			{
				listChuong.Focus();
				Filter_List(listChuong,txtChuong.Text.Trim(),"ma","ten");
				listChuong.BrowseToDmtk(txtChuong,txtTenchuong,txtLoaikhoan,txtChuong.Location.X,txtChuong.Location.Y + txtChuong.Height-2,txtChuong.Width+0+txtTenchuong.Width,txtChuong.Height+i_HChuong,100);
			}
		}

		private void txtChuong_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtChuong && dt_Dmchuong!=null)
			{
				Filter_List(listChuong,txtChuong.Text.Trim(),"ma","ten");
				listChuong.BrowseToDmtk(txtChuong,txtTenchuong,txtLoaikhoan,txtChuong.Location.X,txtChuong.Location.Y + txtChuong.Height-2,txtChuong.Width+0+txtTenchuong.Width,txtChuong.Height+i_HChuong,100);
			}	
		}

		private void txtChuong_Validated(object sender, System.EventArgs e)
		{
			txtTenchuong.Text="";
			if (txtChuong.Text!="")
			{
				r=a.getrowbyid(dt_Dmchuong,"ma='"+txtChuong.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTenchuong.Text=r["ten"].ToString();
				}
			}
			f_Hide_List();
		}

		private void txtLoaikhoan_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (dt_Dmlk!=null)
			{
				if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listLoaikhoan.Focus();
				else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
				{
					if (listLoaikhoan.Visible) 
					{
						listLoaikhoan.Focus();
						SendKeys.Send("{Down}");
					}
					else SendKeys.Send("{Tab}");
				}
			}
			else SendKeys.Send("{Tab}");

		}

		private void txtLoaikhoan_DoubleClick(object sender, System.EventArgs e)
		{
			if (dt_Dmlk!=null)
			{
				listLoaikhoan.Focus();
				Filter_List(listLoaikhoan,txtLoaikhoan.Text.Trim(),"lk","");
				listLoaikhoan.BrowseToDmtk(txtLoaikhoan,txtTenloaikhoan,txtHoatdong,txtLoaikhoan.Location.X,txtLoaikhoan.Location.Y + txtLoaikhoan.Height-2,txtLoaikhoan.Width+0+txtTenloaikhoan.Width,txtLoaikhoan.Height+i_HLoaikhoan,100);
			}
		}

		private void txtLoaikhoan_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtLoaikhoan && dt_Dmlk!=null)
			{
				Filter_List(listLoaikhoan,txtLoaikhoan.Text.Trim(),"lk","");
				listLoaikhoan.BrowseToDmtk(txtLoaikhoan,txtTenloaikhoan,txtHoatdong,txtLoaikhoan.Location.X,txtLoaikhoan.Location.Y + txtLoaikhoan.Height-2,txtLoaikhoan.Width+0+txtTenloaikhoan.Width,txtLoaikhoan.Height+i_HLoaikhoan,100);
			}	
		}

		private void txtLoaikhoan_Validated(object sender, System.EventArgs e)
		{
			txtTenloaikhoan.Text="";
			if (txtLoaikhoan.Text!="")
			{
				r=a.getrowbyid(dt_Dmlk,"lk='"+txtLoaikhoan.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTenloaikhoan.Text=r["tlk"].ToString();
				}
			}
			f_Hide_List();
		}

		private void txtHoatdong_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (dt_Dmhoatdong!=null)
			{
				if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listHoatdong.Focus();
				else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
				{
					if (listHoatdong.Visible) 
					{
						listHoatdong.Focus();
						SendKeys.Send("{Down}");
					}
					else SendKeys.Send("{Tab}");
				}
			}
			else SendKeys.Send("{Tab}");
		}

		private void txtHoatdong_DoubleClick(object sender, System.EventArgs e)
		{
			if (dt_Dmhoatdong!=null)
			{
				listHoatdong.Focus();
				Filter_List(listHoatdong,txtHoatdong.Text.Trim(),"ma","ten");
				listHoatdong.BrowseToDmtk(txtHoatdong,txtTenhoatdong,cboNhombc,txtHoatdong.Location.X,txtHoatdong.Location.Y + txtHoatdong.Height-2,txtHoatdong.Width+0+txtTenhoatdong.Width,txtHoatdong.Height+i_HHoatdong,100);
			}
		}

		private void txtHoatdong_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtHoatdong && dt_Dmhoatdong!=null)
			{
				Filter_List(listHoatdong,txtHoatdong.Text.Trim(),"ma","ten");
				listHoatdong.BrowseToDmtk(txtHoatdong,txtTenhoatdong,cboNhombc,txtHoatdong.Location.X,txtHoatdong.Location.Y + txtHoatdong.Height-2,txtHoatdong.Width+0+txtTenhoatdong.Width,txtHoatdong.Height+i_HHoatdong,100);
			}	
		}

		private void txtHoatdong_Validated(object sender, System.EventArgs e)
		{
			txtTenhoatdong.Text="";
			if (txtHoatdong.Text!="")
			{
				r=a.getrowbyid(dt_Dmhoatdong,"ma='"+txtHoatdong.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTenhoatdong.Text=r["ten"].ToString();
				}
			}
			f_Hide_List();
		}

		private void cboChonthang_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				switch (cboChonthang.SelectedIndex)
				{
					case 0:
						lblTuthang.Enabled=true; numTuthang.Enabled=true;
						lblDenthang.Enabled=true; numDenthang.Enabled=true;
						lblTuthang.Text="Từ tháng"; lblDenthang.Text="đến";
						numTuthang.Maximum=12; numTuthang.Minimum=1;
						numDenthang.Maximum=12; numDenthang.Minimum=1;
						numTuthang.Value=DateTime.Now.Month;
						numDenthang.Value=DateTime.Now.Month;
						numNam.Value=DateTime.Now.Year;
						//numTuthang.Focus();
						break;
					case 1:
						lblTuthang.Enabled=false; numTuthang.Enabled=false;
						lblDenthang.Enabled=true; numDenthang.Enabled=true;
						lblTuthang.Text="Từ tháng"; lblDenthang.Text="Quý";
						numTuthang.Maximum=12; numTuthang.Minimum=1;
						numDenthang.Maximum=4; numDenthang.Minimum=1;
						int i_Quy=(int)((int.Parse(DateTime.Now.Month.ToString())-1)/3)+1;
						numDenthang.Value=i_Quy;
						numNam.Value=DateTime.Now.Year;
						//numDenthang.Focus();
						break;
					case 2:
						lblTuthang.Enabled=false; numTuthang.Enabled=false;
						lblDenthang.Enabled=false; numDenthang.Enabled=false;
						lblTuthang.Text="Từ tháng"; lblDenthang.Text="đến";
						numTuthang.Maximum=12; numTuthang.Minimum=1;
						numDenthang.Maximum=12; numDenthang.Minimum=1;
						numNam.Value=DateTime.Now.Year;
						//numNam.Focus();
						break;
					default:
						lblTuthang.Enabled=true; numTuthang.Enabled=true;
						lblDenthang.Enabled=true; numDenthang.Enabled=true;
						lblTuthang.Text="Từ tháng"; lblDenthang.Text="đến";
						numTuthang.Maximum=12; numTuthang.Minimum=1;
						numDenthang.Maximum=12; numDenthang.Minimum=1;
						numTuthang.Focus();
						break;
				}
			}
			catch{}	;
		}

		#endregion Xu ly list.

		private bool Kiemtra()
		{
			if ((cboChonthang.SelectedIndex==0)&&(numTuthang.Value>numDenthang.Value))
			{
					MessageBox.Show("Bạn đã chọn từ tháng lớn hơn đến tháng!","Chú ý!");
					numDenthang.Focus();
					return false;
			}
			return true;
		}

		private void Display(int i_Loai)
		//Loai display: 1 - xuat ra man hinh; 2 - xuat sang excel ; 3 - xuat ra may in. 
		{
			if (Kiemtra()) //Kiem tra dieu kien nhap vao.
			{
				//Gan dieu kien vao cac bien.
				string s_IDlk="",s_IDchuong="",s_IDhoatdong="",s_IDnhombc="";
			
				frmBangcandoitk_class accMyform=new frmBangcandoitk_class();
				ds_Data=new System.Data.DataSet();
				//Gan dieu kien ngay thang cho cac bien.
				int yy=int.Parse(numNam.Value.ToString());
				int mm1=int.Parse(numTuthang.Value.ToString());
				int mm2=int.Parse(numDenthang.Value.ToString());
				//Tinh lai cac gia trin thang theo dieu kien chon ngay thang.
				switch (cboChonthang.SelectedIndex)
				{
					case 1:
						mm1=(mm2*3)-2;
						mm2=mm2*3;
						break;
					case 2:
						mm1=1;
						mm2=12;
						break;
				}

				string s_mm1=mm1.ToString().PadLeft(2,'0');
				string s_mm2=mm2.ToString().PadLeft(2,'0');
				string s_yyyy=yy.ToString().Trim();
				string s_yy=s_yyyy.Substring(2,2);

				//Kiem tra va canh bao cac thang chua tinh so du.
				string s_Thangnam=a.kt_Tinhsodu(mm1.ToString(),s_yy);
				if (s_Thangnam!="")
				{
					MessageBox.Show("Các tháng "+s_Thangnam.Substring(0,s_Thangnam.Length-1)+" chưa tính số dư!","Chú ý!");
					//xac minh co tinh so du
					if (MessageBox.Show ("Bạn có muốn kiểm tra số dư không ?",this.Text,MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
					{
						//tinh so du
						string sql="",_tu="",_den="";
						_den=s_mm2+s_yyyy.Substring(2,2);			
						//lay thang tu						
						sql="select mmyy from (select *  from a_dtsd where substr(trim(mmyy),3,4)='"+s_yy+"' order by mmyy asc) where rownum=1";
						DataSet ds=new DataSet();
						ds=a.get_data(sql);
						if(ds!=null && ds.Tables[0].Rows.Count>0)
							_tu=ds.Tables[0].Rows[0]["mmyy"].ToString();
						else _tu=s_mm1+s_yyyy.Substring(2,2);			
						if (!a.bYyyy(s_yyyy))
						{
							MessageBox.Show("Số liệu năm "+s_yyyy+" chưa tạo !",a.Msg);
							return;
						}
						string s=a.KiemtraFb(_tu,_den);
						if (s!="")
						{
							MessageBox.Show("Số liệu tháng :"+s.Substring(0,s.Length-1)+" Năm "+s_yyyy+" bị khóa !");    		
							return;
						}
						else 
						{
							Cursor=Cursors.WaitCursor;
							a.KiemtraFb(_tu,_den,i_userid);
							Cursor=Cursors.Default;
						}
						//a.updSodu(_tu,a.Mmyy_sau(_den),i_Iduser,false);
						MessageBox.Show("Đã kiểm tra số dư cuối tháng "+_tu.Substring(0,2)+" đến tháng "+_den.Substring(0,2)+" năm 20"+s_yy+" !",a.Msg);					
						//
					}
					return;
				}

				if (txtChuong.Text.Trim()!="") s_IDchuong=a.getrowbyid(dt_Dmchuong,"ma='"+txtChuong.Text.Trim()+"'")["id"].ToString().Trim();
				if (txtLoaikhoan.Text.Trim()!="") s_IDlk=a.getrowbyid(dt_Dmlk,"lk='"+txtLoaikhoan.Text.Trim()+"'")["id"].ToString().Trim();
				if (txtHoatdong.Text.Trim()!="") s_IDhoatdong=a.getrowbyid(dt_Dmhoatdong,"ma='"+txtHoatdong.Text.Trim()+"'")["id"].ToString().Trim();
				if (cboNhombc.SelectedIndex>=0) s_IDnhombc=cboNhombc.SelectedValue.ToString();

				//Load data cua tung mau bao cao.
				switch (s_Tenform)
				{
					case "BCDTK": 
						ds_Data=accMyform.f_Bangcandoitaikhoan(a,s_IDchuong,s_IDlk,s_IDhoatdong,s_IDnhombc,s_mm1,s_mm2,s_yy,chkChitiet.Checked);
						accMyform.Dispose();
						break;
					default:
						ds_Data.Clear();
						ds_Data.Dispose();
						break;
				}
				//Ghi DataSet ra file xml de lay cau truc lam report.
				//ds_Data.WriteXml("..\\..\\xml_data\\KT_Bangcandoitk2.xml",XmlWriteMode.WriteSchema);

				try
				{
					if (ds_Data==null || ds_Data.Tables[0].Rows.Count==0) MessageBox.Show("Không có số liệu !","Thông báo !");
					else
					{
						string s_fTinhchat_tk="0";
						string s_fNgaythang="",s_fGiatri11="",s_fGiatri12="",s_fGiatri21="",s_fGiatri22="";
						string s_fGiatri31="",s_fGiatri32="",s_fGiatri41="",s_fGiatri42="",s_fGiatri51="",s_fGiatri52="";
						f_Loadformula(mm1,mm2,yy,ref s_fTinhchat_tk,ref s_fNgaythang,ref s_fGiatri11,
							ref s_fGiatri12,ref s_fGiatri21,ref s_fGiatri22,ref s_fGiatri31,ref s_fGiatri32,
							ref s_fGiatri41,ref s_fGiatri42,ref s_fGiatri51,ref s_fGiatri52);
						
						switch (i_Loai) //i_Loai: 1 - xuat ra man hinh; 2 - xuat sang excel ; 3 - xuat ra may in. 
						{
							case 1:
								frmReport_kt f=new frmReport_kt(a,ds_Data,s_fTieude_chinh,s_fNgaythang,s_fTinhchat_tk,s_fGiatri11,s_fGiatri12,s_fGiatri21,s_fGiatri21,s_fGiatri31,s_fGiatri32,s_fGiatri41,s_fGiatri42,s_fGiatri51,s_fGiatri52,s_Report.ToString());
								f.ShowDialog();
								break;
							case 2:
								string s_ExcelError=exportExcel.expExcel(a,ds_Data,s_fTieude_chinh,s_fNgaythang,s_fTinhchat_tk,s_fGiatri11,s_fGiatri12,s_fGiatri21,s_fGiatri21,s_fGiatri31,s_fGiatri32,s_fGiatri41,s_fGiatri42,s_fGiatri51,s_fGiatri52,s_Report.ToString());
								if (s_ExcelError!="")
									MessageBox.Show(s_ExcelError,"Thông báo!");
								break;
							case 3:
								string s_InError=Print.Printer(a,ds_Data,s_fTieude_chinh,s_fNgaythang,s_fTinhchat_tk,s_fGiatri11,s_fGiatri12,s_fGiatri21,s_fGiatri21,s_fGiatri31,s_fGiatri32,s_fGiatri41,s_fGiatri42,s_fGiatri51,s_fGiatri52,s_Report.ToString(),s_Pagesize,i_Kieuin,i_Banin); //Kieu - ngang hoac doc ; Copy - so ban in.
								if (s_InError=="")
									MessageBox.Show("Đã in xong báo cáo","Thông báo!");
								else MessageBox.Show(s_InError,"Lỗi in báo cáo!");
								break;
							default:
								f=new frmReport_kt(a,ds_Data,s_fTieude_chinh,s_fNgaythang,s_fTinhchat_tk,s_fGiatri11,s_fGiatri12,s_fGiatri21,s_fGiatri21,s_fGiatri31,s_fGiatri32,s_fGiatri41,s_fGiatri42,s_fGiatri51,s_fGiatri52,s_Report.ToString());
								f.ShowDialog();
								break;
						}
					}
				}
				catch
				{
					MessageBox.Show("Không có số liệu !","Thông báo !");
				}
			}
		}

		private void f_Loadformula(int mm1,int mm2,int yy,
			ref string s_fTinhchat_tk,ref string s_fNgaythang,ref string s_fGiatri11,
			ref string s_fGiatri12,ref string s_fGiatri21,ref string s_fGiatri22,ref string s_fGiatri31,
			ref string s_fGiatri32,ref string s_fGiatri41,ref string s_fGiatri42,ref string s_fGiatri51,ref string s_fGiatri52)
		{
			s_fTinhchat_tk="";
			if (cboChonthang.SelectedIndex==0)
			{
				if (mm1==mm2) s_fNgaythang="Tháng "+mm1.ToString()+" năm "+yy.ToString();
				else s_fNgaythang="Từ tháng "+mm1.ToString()+" đến tháng "+mm2.ToString()+" năm "+yy.ToString();
			}
			else if (cboChonthang.SelectedIndex==1)
					s_fNgaythang="Quý "+numDenthang.Value.ToString()+" năm "+yy.ToString();
				else s_fNgaythang="Năm "+yy.ToString();
			if(cboNhombc.Text!="")
			s_fGiatri11=cboNhombc.Text;
			else 
				s_fGiatri11="Tổng Hợp";
			s_fGiatri12="";
						
			if (txtLoaikhoan.Text.Trim()!="") 
			{
				s_fGiatri21=txtLoaikhoan.Text.Trim().Split('-')[0].ToString();
				s_fGiatri22=txtLoaikhoan.Text.Trim().Split('-')[1].ToString();
			}
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			Display(1);
		}

		private void butExcel_Click(object sender, System.EventArgs e)
		{
			Display(2);
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			Display(3);
		}

		private void frmBangcandoitk_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			try
			{
				if (a!=null) a.Dispose();
				ds_Data.Dispose();
			}
			catch{}	;
			this.Dispose();
		}
	}
}
